package web.encriptacion;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import utils.Encriptador;

public class EncriptacionLink extends WebPage{
	private static final long serialVersionUID = 1L;
	private String variable;

	public EncriptacionLink(PageParameters parametros) {
		variable = RequestCycle.get().getRequest().getQueryParameters().getParameterValue("documento").toString();
		add(
			algoritmo(),
			encriptada(),
			desencriptada(),
			linkVolver()
		);
	}

	private Component linkVolver() {
		return new Link<Void>("volver") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick() {
				setResponsePage(EncriptacionHome.class);
			}
		};
	}

	private Component desencriptada() {
		IModel<String> modelo = new AbstractReadOnlyModel<String>() {
			private static final long serialVersionUID = 1L;

			@Override
			public String getObject() {
				return Encriptador.get().desencriptar(variable);
			}
		};
		return new Label("variable_desencriptada", modelo);
	}

	private Component encriptada() {
		IModel<String> modelo = new PropertyModel<String>(this, "variable");
		return new Label("variable_encriptada", modelo);
	}

	private Component algoritmo() {
		IModel<String> modelo = new PropertyModel<String>(Encriptador.get(), "tipoLlave");
		return new Label("algoritmo", modelo);
	}


	
	//getters y setters
	public void setVariable(String variable) {
		this.variable = variable;
	}
	
	public String getVariable() {
		return variable;
	}
}